package com.wind.plugin.openAction.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

public class CDataSerializer extends StdSerializer<String> {

    public CDataSerializer() {
        this(null);
    }

    public CDataSerializer(Class<String> t) {
        super(t);
    }

    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        if (value != null) {
            gen.writeStartObject();
            gen.writeRaw("\n<![CDATA[");
            gen.writeRaw(value);
            gen.writeRaw("]]>\n");
            gen.writeEndObject();
        } else {
            gen.writeString("");
        }
    }
}